﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditCargoFrm.aspx.cs" Inherits="WebApp.EditCargoFrm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>货物资料</title>
    <link rel="stylesheet" type="text/css" href="css/newStyle.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/icon.css" />

    <script type="text/javascript" src="js/common.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery-1.8.0.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="js/Jquery.Query.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            initParams();
        });

        function initParams() {
            var cargoId = $.query.get('CargoId');
            var caseId = $.query.get('CaseId');
            var orderId = $.query.get('OrderId');
            $('#orderId').val(orderId);
            $('#caseId').val(caseId);
            $('#editId').val(cargoId);
            initData();
            bindCase();
        }

        function bindCase() {
            var id = $('#editId').val();
            if (id) {
                WebApp.EditCargoFrm.GetCargo(id, function callback(p) {
                    if (p.error) {
                        $.messager.alert('异常消息', '获取数据异常,' + p.error.Message, 'error');
                        return;
                    }

                    var res = p.value;
                    if (res) {
                        var data = res.Data;
                        var msg = res.Msg;
                        if (msg)
                            $.messager.alert('货物信息获取异常', msg, 'error');
                        else {
                            if (data) {
                                $('#eCargoName').val(data.cargoName);
                                $('#eAmount').val(data.amount);
                                $('#eHairWeight').val(data.hairWeight);
                                $('#eNetWeight').val(data.netWeight);
                                $('#eVolume').val(data.volume);
                                $('#ePackageType').combobox('setValue', data.packageType);
                                $('#eCaseAmount').val(data.caseAmount);
                                $('#eMarker').val(data.marker);
                                $('#eCaseMemo').val(data.memo);
                            }
                        }
                    }
                });
            }
        }

        function initData() {
            $.getJSON("JSONHandler.ashx?DataType=PackageType", function(result) {
                $('#ePackageType').combobox('loadData', result);
            });
        }

        function resetFrm() {
            $('#fm').form('clear');
        }

        function addCase() {
            resetFrm();
        }

        function saveCargo() {
            var validate = $('#fm').form('validate');
            if (!validate)
                return;
            var id = $('#editId').val();
            var orderId = $('#orderId').val();
            var caseId = $('#caseId').val();
            var eCargoName = $('#eCargoName').val();
            var eAmount = $('#eAmount').val();
            var eHairWeight = $('#eHairWeight').val();
            var eNetWeight = $('#eNetWeight').val();
            var eVolume = $('#eVolume').val();
            var ePackageType = $('#ePackageType').combobox('getValue');
            var eCaseAmount = $('#eCaseAmount').val();
            var eMarker = $('#eMarker').val();
            var eCaseMemo = $('#eCaseMemo').val();

            WebApp.EditCargoFrm.SaveCargo(id, caseId, orderId, eCargoName, eAmount, eHairWeight, eNetWeight, eVolume, ePackageType, eCaseAmount, eMarker, eCaseMemo, function callback(p) {
                if (p.error) {
                    $.messager.alert('异常消息', '提交保存异常,' + p.error.Message, 'error');
                    return;
                }

                var res = p.value;
                if (res) {
                    var data = res.Data;
                    var msg = res.Msg;
                    if (msg)
                        $.messager.alert('货物信息获取异常', msg, 'error');
                    else {
                        refreshParent(caseId);
                        if (id) {
                            if (data > 0) {
                                $.messager.alert('消息', '货物信息已更新!', 'info');
                                $('#editId').val(data);
                            }
                            else
                                $.messager.alert('货物信息更新异常', msg, 'error');
                        }
                        else {
                            if (data > 0) {
                                $.messager.alert('消息', '货物信息已创建!', 'info');
                                $('#editId').val(data);
                            }
                            else
                                $.messager.alert('货物信息创建异常', msg, 'error');
                        }
                    }
                }
            });
        }

        function deleteCargo() {
            var id = $('#editId').val();
            var orderId = $('#orderId').val();
            WebApp.EditCargoFrm.DeleteCargo(id, orderId, function callback(p) {

                if (p.error) {
                    $.messager.alert('异常消息', '提交删除异常,' + p.error.Message, 'error');
                    return;
                }
                var res = p.value;
                if (res) {
                    var data = res.Data;
                    var msg = res.Msg;
                    if (msg)
                        $.messager.alert('删除异常', msg, 'error');
                    else {
                        if (data == true) {
                            $.messager.alert('消息', '货物信息已删除!', 'info');
                            refreshParent(orderId);
                        }
                        else
                            $.messager.alert('删除箱号失败', msg, 'error');
                    }
                }
            });
        }

        function refreshParent(caseId) {
            window.parent.bindCargo(caseId);
        }
    </script>

</head>
<body>
    <form id="Form1" method="post" runat="server">
    </form>
    <div>
        <form id="fm">
        <div style="padding: 5px; border: 1px solid #ddd">
            <a href="#" id="btnAdd" class="easyui-linkbutton" data-options="plain:true" onclick="addCargo()">
                新增</a> <a href="#" id="btnSave" class="easyui-linkbutton" data-options="plain:true"
                    onclick="saveCargo()">保存</a> <a href="#" id="btnDelete" class="easyui-linkbutton"
                        data-options="plain:true" onclick="deleteCargo()">删除</a>
        </div>
        <div class="easyui-panel" title="货物资料" style="width: 500px; padding: 5px;">
            <table>
                <tr>
                    <td style="text-align: left">
                        货名：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eCargoName" style="width: 150px" class="easyui-validatebox"
                            data-options="required:true" />
                    </td>
                    <td style="text-align: left">
                        数量：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eAmount" style="width: 150px" class="easyui-validatebox"
                            data-options="required:true" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        毛重：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eHairWeight" style="width: 150px" class="easyui-validatebox"
                            data-options="required:true" />
                    </td>
                    <td style="text-align: left">
                        净重：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eNetWeight" style="width: 150px" class="easyui-validatebox"
                            data-options="required:true" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        体积：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eVolume" style="width: 150px" class="easyui-validatebox"
                            data-options="required:true" />
                    </td>
                    <td style="text-align: left">
                        包装：
                    </td>
                    <td style="text-align: left">
                        <input class="easyui-combobox" id="ePackageType" data-options="valueField:'id',textField:'name'"
                            style="width: 150px;">
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        箱量：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eCaseAmount" style="width: 150px" />
                    </td>
                    <td style="text-align: left">
                        唛头：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eMarker" style="width: 150px" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        备注：
                    </td>
                    <td style="text-align: left" colspan="3">
                        <input type="text" id="eMemo" style="width: 250px" />
                    </td>
                </tr>
            </table>
        </div>
        <input id="editId" type="hidden" />
        </form>
        <input id="caseId" type="hidden" />
        <input id="orderId" type="hidden" />
    </div>
</body>
</html>
